#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class FiveHundredEleven {
public:
	string theWinner(vector <int>);
	int N;
	vector<int> c;
	int visited[512][51];
	
	int winning(int mem, int played){
		if(mem==511) return 1;
		if(played==N) return 0;
		int &ret = visited[mem][played];
		if(ret != -1) return ret;
		int cnt = 0;
		for(int i=0; i<N; i++) 
			if((mem | c[i]) == mem)
				cnt++;
		if(cnt > played && !winning(mem, played+1)) return ret = 1;
		for(int i=0; i<N; i++){
			if((mem | c[i]) != mem && !winning(mem|c[i], played+1))
				return ret = 1;
		}
		return ret = 0;
	}
};

string FiveHundredEleven::theWinner(vector <int> cards) {
	N = cards.size();
	c = cards;
	memset(visited, -1, sizeof(visited));
	if(winning(0, 0)) return "Fox Ciel";
	return "Toastman";
}


double test0() {
	int t0[] = {3, 5, 7, 9, 510};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	FiveHundredEleven * obj = new FiveHundredEleven();
	clock_t start = clock();
	string my_answer = obj->theWinner(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string p1 = "Fox Ciel";
	cout <<"Desired answer: " <<endl;
	cout <<"\t\"" << p1 <<"\"" <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t\"" << my_answer<<"\"" <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test1() {
	int t0[] = {0, 0, 0, 0};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	FiveHundredEleven * obj = new FiveHundredEleven();
	clock_t start = clock();
	string my_answer = obj->theWinner(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string p1 = "Toastman";
	cout <<"Desired answer: " <<endl;
	cout <<"\t\"" << p1 <<"\"" <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t\"" << my_answer<<"\"" <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test2() {
	int t0[] = {511};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	FiveHundredEleven * obj = new FiveHundredEleven();
	clock_t start = clock();
	string my_answer = obj->theWinner(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string p1 = "Toastman";
	cout <<"Desired answer: " <<endl;
	cout <<"\t\"" << p1 <<"\"" <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t\"" << my_answer<<"\"" <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test3() {
	int t0[] = {5, 58, 192, 256};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	FiveHundredEleven * obj = new FiveHundredEleven();
	clock_t start = clock();
	string my_answer = obj->theWinner(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string p1 = "Fox Ciel";
	cout <<"Desired answer: " <<endl;
	cout <<"\t\"" << p1 <<"\"" <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t\"" << my_answer<<"\"" <<endl;
	if (p1 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}

int main() {
	int time;
	bool errors = false;
	
	time = test0();
	if (time < 0)
		errors = true;
	
	time = test1();
	if (time < 0)
		errors = true;
	
	time = test2();
	if (time < 0)
		errors = true;
	
	time = test3();
	if (time < 0)
		errors = true;
	
	if (!errors)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}

//Powered by [KawigiEdit] 2.0!
